/***************************************************************************
 *   Copyright (C) 2008 by Ryszard Krol   *
 *   rysiek.krol@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/


#ifndef PICTUREMANAGER_H
#define PICTUREMANAGER_H

#include <QMainWindow>
#include <QCloseEvent>
#include <QEvent>
#include <QList>
#include <QFileInfo>
#include "property.h"


class PictureListWidgetItem;
class QAction;
class QMenu;
class QListWidget;
class QListWidgetItem;
class QDir;
class QModelIndex;
class ImageReader;
class QTreeView;
class QListView;
class QSplitter;
class QStyle;
class QFileInfo;
class QScrollArea;
class ImageLoader;
class QLabel;
class QComboBox;
class FileOperationsHandler;
class ProgressBarDialogs;
class DisplayOperations;
class PresentationWindow;
class EventHandler;
class FilesOperations;

class PictureManager:public QMainWindow
{
    Q_OBJECT

    friend class DisplayOperations;
    friend class EventHandler;

public:
    PictureManager(QStyle *styl);
    PictureManager(QStyle *styl, QString filePath);
    ~PictureManager();
    QListWidget *getListWidget();
    void setStyl(QStyle  *theValue);
    QStyle * getStyl();
    QLabel* getPresentationWidget() const;
    void setIsPresentationMode(bool theValue);
    bool getIsPresentationMode() const;
    Property* getItsProperty() const;
    QDir* getCurDir() const;
    ImageReader* getItsReader() const;
    void displayImage(QPixmap pixmap);
    void switchGuiToPresentationMode(QFileInfo *fileInfo);
    void setIsAlbumViewer(bool theValue);
    DisplayOperations* getDisplayOperations() const;
    bool getIsAlbumViewer() const;
    ImageLoader* getItsLoader() const;
    EventHandler* getEventHandler() const;
    FilesOperations* getFilesOperations() const;
    QTreeView* getTreeWidget() const;

public slots:
    void reLoadSlot();
    void fullScreenSwichSlot();

protected:
    void keyPressEvent(QKeyEvent * event);
    void resizeEvent( QResizeEvent * event );
    void mousePressEvent( QMouseEvent * event );
    void wheelEvent ( QWheelEvent * event );

private slots:
    void listClicked ( QListWidgetItem * item );
    void listClicked (  const QModelIndex & index );
    void about();
    void renameDialog();
    void treeClicked ( const QModelIndex & index );
    void switchGuiToBrowserMode();
    void goBackSlot();
    void goUpSlot();
    void editComment();
    void removeCommentSlot();
    void closeEvent(QCloseEvent * event );
    void PropertyDialogOpenSlot();
    void sortingMethodChangedSlot(int index);
    void makeDirectorySlot();
    void saveImageSlot();

private:
    void createActions();
    void createMenus();
    void createToolBars();
    void createStatusBar();
    void customEvent ( QEvent *event );
    void contextMenuEvent ( QContextMenuEvent *event );
    void buildBrowserWidget();
    void reLoadBrowser();
    void listClicked(QFileInfo *file);


    int findItem(QFileInfo *fileInfo);
    void loadImage(int index);
    void initializeGUI(QStyle * styl);

    QStyle *styl;
    ProgressBarDialogs *progressBarDialogs;
    FileOperationsHandler *itsFilesHandler;
    ImageReader *itsReader;
    ImageLoader *itsLoader;
    QListWidget *listWidget;
    QListView *listView;
    QTreeView *treeWidget;
    QSplitter *browserWidget;
    QLabel *presentationWidget;
    QScrollArea *scrollArea;
    QComboBox *sortingCombo;
    DisplayOperations *displayOperations;
    FilesOperations *filesOperations;
    PresentationWindow *itsPesentationWindow;
    EventHandler *itsEventHandler;

    Property *itsProperty;
    QDir *curDir;
    QDir *oldDir;
    QMenu *fileMenu;
    QMenu *editMenu;
    QMenu *helpMenu;
    QToolBar *browserToolBar;
    QToolBar *presentationToolBar;
    QToolBar *sortingToolBar;
    QToolBar *imageManipulationToolBar;
    QToolBar *commentToolBar;

    bool isAlbumViewer;
    bool fullScreen;
    bool isPresentationMode;

    QAction *renameAct;
    QAction *exitAct;
    QAction *aboutAct;
    QAction *aboutQtAct;
    QAction *closePresentaionAct;
    QAction *displayNextImageAct;
    QAction *displayPreviousImageAct;
    QAction *goBackAct;
    QAction *goUpAct;
    QAction *reLoadBrowserAct;
    QAction *goToFullScreenAct;
    QAction *commentEditAct;
    QAction *commentRemoveAct;
    QAction *PropertyDialogOpenAct;
    QAction *sortingMethodChangedAct;
    QAction *removeFilesAct;
    QAction *copyFilesAct;
    QAction *moveFilesAct;
    QAction *makeDirectoryAct;
    QAction *rotate90Act;
    QAction *rotate180Act;
    QAction *rotate270Act;
    QAction *saveImageAct;
    QAction *slideShowAct;
    QAction *keywordsAct;
    QAction *searchAct;
    QAction *imagePropertyDialogAct;
    QAction *copyAct;
    QAction *cutAct;
    QAction *pasteAct;
};

#endif
